<{include file="public/header.html"}>
		<div class="xinsu-section">
			<div class="xinsu-equity">
				<ul class="xinsu-cross-title">
					<li <{if $common_info.action == 'index'}>class="xinsu-current"<{/if}>><a href="/stock">持仓单</a></li>
					<li <{if $common_info.action == 'trust'}>class="xinsu-current"<{/if}>><a href="/stock/trust">委托单</a></li>
					<li <{if $common_info.action == 'delivery'}>class="xinsu-current"<{/if}>><a href="/stock/delivery">交割单</a></li>
					<div class="xinsu-clear"></div>
				</ul>
				<div class="xinsu-equity-con">
					<{if empty($list) == false}>
					<{foreach $list as $val}>
					<div class="xinsu-equity-list" id="xinsu-stock-<{$val.id}>" data="<{$val.id}>">
						<div class="xinsu-equity-list-title">
							<span>编号：<{$val.id}></span>
							<p>建仓时间：<{date("Y-m-d H:i:s", $val.bull_time)}></p>
						</div>
						<ul>
							<li>
								<p>股票名称：<{$val.stock_name}></p>
								<p>买入价：<{$val.bull_price}></p>
								<p>最新价：<span class="xinsu-color-red" id="xinsu-price-<{$val.id}>">--</span></p>
							</li>
							<li>
								<p>类型：<{if $val.bull_type == 1}><span class="xinsu-color-red">融资↑</span><{else}><span class="xinsu-color-green">融券↓</span><{/if}>（<{$val.bull_num}>）</p>
								<p>盈亏：<span id="xinsu-gain-<{$val.id}>">--</span></p>
								<p>结算天/费：<span class="xinsu-color-red" id="xinsu-save-<{$val.id}>">--</span></p>
							</li>
							<div class="xinsu-clear"></div>
						</ul>
						<div>
							<div style="background-color: #e66e61;text-align: center;margin: 5px;border-radius: 10px;height: 44px;line-height: 44px;">
								<a id="xinsu-mange-<{$val.id}>" class="xinsu-sell xinsu-block-sell" href="javascript:;" data="<{$val.id}>" data-num="共<{$val.bull_num}>（股） 已委托 <{$val.bull_num - $val.can_sell_num - $val.sell_num}>（股） 可卖：<{$val.can_sell_num}>（股）" data-bull-time="<{date('Y-m-d H:i:s',$val['bull_time'])}>" data-price="<{$val.bull_price}>" data-bulltype="<{$val.bull_type}>" data-stock="<{$val.stock}>" data-cannum="<{$val.can_sell_num}>" data-stockname="<{$val.stock_name}>"><{if $val.bull_type == 1}><span  style="color: white;font-size: 16px;">卖券还款<span><{else}><span
                                        style="color: white;font-size: 16px;">买券还券
                                    <span><{/if}>
								</a>
							</div>
						</div>
					</div>
					<{/foreach}>
					<{/if}>
				</div>
			</div>
		</div>
		<script>
			$(function(){
				get_stock();
			})
			var stock = 0;
			
			//获取最新价格
			function get_stock() {
				if (stock >= 0) {
					var url = "/stock/ajax_get_bull";
					var data = "";
					$(".xinsu-equity-list").each(function(){
						var tmp = $(this).attr("data");
						if (tmp != undefined) {
							data += "," + tmp;
						}
					})
					http_request_post(url, {data:data}, function(res) {
						var result = res.data;
						if (res.status == 1) {
							//列表
							$.each(result, function(key, val){
								var bull_type = $("#xinsu-mange-" + key).attr("data-bulltype");
								if (val.price > 0) {
									$("#xinsu-price-" + key).html(val.price);
									if (val.gain > 0) {
										$("#xinsu-gain-" + key).addClass("xinsu-color-red").removeClass("xinsu-color-green");
									} else {
										$("#xinsu-gain-" + key).addClass("xinsu-color-green").removeClass("xinsu-color-red");
									}
									$("#xinsu-gain-" + key).html(val.gain);
									$("#xinsu-save-" + key).html(val.save);
									$("#xinsu-mange-" + key).addClass("xinsu-block-sell").removeClass("xinsu-block-disabled");
									if (bull_type == 1) {
										$("#xinsu-mange-" + key).html('<span style="color: white;font-size: 16px;">卖券还款<span>');
									} else {
										$("#xinsu-mange-" + key).html('<span style="color: white;font-size: 16px;">买券还券<span>');
									}
								} else {
									$("#xinsu-price-" + key).html("--");
									$("#xinsu-gain-" + key).html("--");
									$("#xinsu-save-" + key).html("--");
									$("#xinsu-mange-" + key).html("停牌");
									$("#xinsu-mange-" + key).removeClass("xinsu-block-sell").addClass("xinsu-block-disabled");
								}
							})
							
							setTimeout("get_stock();", 1000);
						}
					});
				}
				
			}

			//平仓
			$(".xinsu-block-sell").click(function(){
				var id = $(this).attr("data");
				var num = $(this).attr("data-num");
				var stock = $(this).attr("data-stock");
				var stock_name = $(this).attr("data-stockname");
				var can_sell_num = $(this).attr("data-cannum");
				var bull_price = $(this).attr("data-price");
				var bull_time = $(this).attr("data-bull-time");
				var bull_type = $(this).attr("data-bulltype");
				if (bull_type == 1) {
					var title = "卖券还款";
					bull_type = '<span class="xinsu-color-red">融资↑</span>';
				} else {
					var title = "买券还券";
					bull_type = '<span class="xinsu-color-green">融券↓</span>';
				}
				var price = $("#xinsu-price-" + id).html();
				if (price == "--") {
					layer.msg("该股票已停牌，禁止交易");return false;
				}
				//弹出卖出
				layer.open({
					type: 1,
					title: title,
					area: ['90%', ''],
					btn:['确定', '取消'],
					shadeClose: true, //点击遮罩关闭
					content: '<div class="xinsu-sell-open"><form class="weui-cells xinsu-cells" method="post"><div class="weui-cell"><div class="weui-cell__bd"><p>股票名称：'+stock_name+'</p></div></div><div class="weui-cell"><div class="weui-cell__bd"><p>股票代码：'+stock+'</p></div></div><div class="weui-cell"><div class="weui-cell__bd"><p>持仓时间：'+bull_time+'</p></div></div><div class="weui-cell"><div class="weui-cell__bd"><p>持仓数量：'+num+'</p></div></div><div class="weui-cell"><div class="weui-cell__bd"><p>股票类型：'+bull_type+'</p></div></div><div class="weui-cell"><div class="weui-cell__bd"><p>买入价格：<span class="xinsu-color-green">'+bull_price+' 元/股</span></p></div></div><div class="weui-cell"><div class="weui-cell__bd"><p>当前价格：<span class="xinsu-color-red">'+price+'/股</span></p></div></div><div class="weui-cell xinsu-cell"><div class="weui-cell__fl">	<label class="weui-label">卖出价格：</label></div><div class="weui-cell__bd"><input type="radio" name="price_type" value="0" onclick="javascript:$(\'#xinsu-sell-price\').hide();" checked /><span class="xinsu-color-red">市价 </span><input type="radio" name="price_type" value="1" onclick="javascript:$(\'#xinsu-sell-price\').show();" /><span class="xinsu-color-green"> 委托价 </span></div></div><div class="weui-cell xinsu-cell" id="xinsu-sell-price" style="display:none;"><div class="weui-cell__fl"><label class="weui-label">委托价格：</label></div><div class="weui-cell__bd"><input type="text" name="sell_price" id="sell_price" value="'+price+'" class="weui-input xinsu-color-red" placeholder="请输入委托价格" /></div></div><div class="weui-cell xinsu-cell"><div class="weui-cell__fl"><label class="weui-label">卖出数量：</label></div><div class="weui-cell__bd"><input type="text" id="sell_num" name="sell_num" class="weui-input" value="'+can_sell_num+'" placeholder="最大卖出数量'+can_sell_num+'股" /></div></div></form></div>',
					yes:function(index, layers){
						var price_type = $("input[name='price_type']:checked").val();
						var sell_num = $("#sell_num").val();
						var sell_price = $("#sell_price").val();
						//交易类型
						if (price_type == 0) {
							var rmsg = "市价平仓处理成功！";
						} else {
							var rmsg = "限价平仓委托处理成功！";
						}
						http_request_post("/stock/ajax_set_sell", {id:id, sell_num:sell_num, sell_price:sell_price, price_type:price_type, token:token}, function(result){
							layer.closeAll();
							layer.alert(rmsg, {icon:1, closeBtn:0}, function(){
								location.reload();
							});
						});
					}
					
				});
			})
		</script>
<{include file="public/footer.html"}>